package com.dferreira.languagesteach.controllers;

import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class IndexController {

    private static final String USER_AGENT_HEADER = "User-Agent";
    private static final String MSIE_REFERENCE = "MSIE";

    private boolean hasMSIEReference(String userAgent) {
        return userAgent.contains(MSIE_REFERENCE);
    }

    @RequestMapping(method = RequestMethod.GET)
    public String printIntroduction(ModelMap model, HttpServletRequest request) {
        String userAgent;
        userAgent = request.getHeader(USER_AGENT_HEADER);
        model.addAttribute("not_on_internet_explorer", !hasMSIEReference(userAgent));
        return "index";
    }
}
